<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>派送登记</title>
    <link rel="stylesheet" type="text/css" href="../../../../start/layui/css/layui.css"/>
    <style type="text/css">
        .layui-form-select .layui-input {
            padding-right: 0px;
            cursor: pointer;
        }
    </style>
    <script src="../../../../start/layui/layui.js"></script>
    <script src="../../../../start/layui/js/area2.js"></script>
    <script src="../../../../start/layui/js/xcl.js"></script>
</head>
<body>
<form method="post" class="layui-form">
    <div class="layui-row"  style="margin-top: 10px">
        <div class="layui-col-md4">
            <label class="layui-form-label">派送时间</label>
            <div class="layui-input-inline">
                <input type="tel" id="date" placeholder="yyyy-MM-dd"  class="layui-input">
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">所在分站</label>
            <div class="layui-input-inline">
                <select name="substationunit" id="substationUnit">
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">司机姓名</label>
            <div class="layui-input-inline">
                <input type="tel" id="ownername" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-row" style="margin-top: 10px">
        <div class="layui-col-md4">
            <label class="layui-form-label">车辆牌照</label>
            <div class="layui-input-inline">
                <input type="tel" id="licensetag"  class="layui-input">
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">司机电话</label>
            <div class="layui-input-inline">
                <input type="tel"  class="layui-input">
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">车辆类型</label>
            <div class="layui-input-inline">
                <input type="tel" id="vehicleType" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-row" style="margin-top: 10px">
        <div class="layui-col-md4">
            <label class="layui-form-label">托运单号</label>
            <div class="layui-input-inline">
                <input type="tel"  id="waybill_id"  readonly="readonly"  class="layui-input">
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">货运名称</label>
            <div class="layui-input-inline">
                <input type="tel"  id="descriptionGoods" readonly="readonly"  class="layui-input">
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">数量</label>
            <div class="layui-input-inline">
                <input type="tel" id="quantity" readonly="readonly"  class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-row" style="margin-top: 10px">
        <div class="layui-col-md4">
            <label class="layui-form-label">送货地址</label>
            <div class="layui-input-inline">
                <input type="tel" id="remark"  readonly="readonly"  class="layui-input">
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-inline">
                <input type="tel" readonly="readonly"  id="phone" class="layui-input">
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">货运id</label>
            <div class="layui-input-inline">
                <input type="tel" readonly="readonly" id="freightInformation"  class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-row" style="margin-top: 10px">
        <div class="layui-col-md4">
            <label class="layui-form-label">派送成本</label>
            <div class="layui-input-inline">
                <input type="tel" id="cost"  class="layui-input">
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">注意事项</label>
            <div class="layui-input-block">
                <textarea name="desc" placeholder="请输入内容" id="announcements"  class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">&nbsp;</label>
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
        </div>
    </div>
</form>
</body>
</html>
<script>
    layui.use(['form', 'layedit', 'laydate','jquery'], function() {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
        var $ = layui.jquery;
        //日期
        laydate.render({
            elem: '#date'
        });

        //显示网址
        var locationi=location.href;
        //根据下标截取字符串获得id
        var id=locationi.substring(locationi.indexOf("=")+1);
        //所在分站
        $.ajax({
            url: "../../../../getAllSubstation",
            type: "post",
            data: {},
            dataType: "json",
            success: function (data) {
                //动态添加下拉框
                for (var i = 0; i < data.length; i++) {
                    $("#substationUnit").append("<option value='" + data[i].subId + "'>" + data[i].subName + "</option>");
                }
                //刷新
                form.render('select');
                //赋值
                $.ajax({
                    url: "../../../../getFreightinformationTableByid",
                    type: "post",
                    data: {
                        freightInformation:id
                    },
                    dataType: "json",
                    success: function (data) {
                        $('#waybill_id').val(data.waybill_id);
                        $('#descriptionGoods').val(data.descriptionGoods);
                        $('#quantity').val(data.quantity);
                        $('#remark').val(data.remark);
                        $('#freightInformation').val(data.freightInformation);
                        $('#phone').val(data.phone);
                    }
                })
            }
        })





        //提交
        form.on('submit(demo1)', function(data){
            $.ajax({
                url: "../../../../insertDelivery",
                type: "post",
                data:{
                    //车辆牌照
                    licensetag:$('#licensetag').val(),
                    //运单id
                    waybill_id:$('#waybill_id').val(),
                    //司机电话
                    phone:$('#phone').val(),
                    //司机名字
                    ownername:$('#ownername').val(),
                    //车辆类型
                    vehicleType:$('#vehicleType').val(),
                    //派送时间
                    deliverydate:$('#date').val(),
                    //所在分站
                    fenzhan:$('#substationUnit option:selected').val(),
                    //货运id
                    orderinformation:$('#freightInformation').val(),
                    //派送成本
                    cost:$('#cost').val(),
                    //注意事项
                    announcements:$('#announcements').val()
                },
                dataType: "text",
                success: function (data) {
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                    layer.closeAll("iframe");//关闭iframe层
                    //修改成功后刷新父界面
                    window.parent.location.reload();
                }
            })
            return false;
        });
    })
</script>